﻿using Apex.Dapper;
using Dapper.App.Entity;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Reflection;

namespace Dapper.App
{
    internal class Program
    {
        // His库执行器
        private readonly static MapperExecutor mapperExecutor = new MapperExecutor(
            DapperAccess.GetConnection(ConfigurationManager.ConnectionStrings["hisdb"].ConnectionString),
            Assembly.GetExecutingAssembly().GetManifestResourceStream(ConfigurationManager.AppSettings["SqlScript"]));

        // His库执行器[Oracle]
        [Obsolete]
        private readonly static MapperExecutor oracleMapperExecutor = new MapperExecutor(
            DapperAccess.GetOracleConnection(ConfigurationManager.ConnectionStrings["hisdbThird"].ConnectionString),
            Assembly.GetExecutingAssembly().GetManifestResourceStream(ConfigurationManager.AppSettings["SqlScript"]));

        static void Main(string[] args)
        {
            SqlServerTest();
            //OracleTest();
        }

        /// <summary>
        /// Sql Server测试
        /// </summary>
        private static void SqlServerTest()
        {
            /**
            object[] dataSource = new object[]
            {
                new {StaffNo = "500012", StaffName = "张三1"},
                new {StaffNo = "500013", StaffName = "李四2"}
            };
            mapperExecutor.ExecuteNoQuery("AddStaff", dataSource);// 批量插入
            */
            //mapperExecutor.ExecuteBatch("AddStaffBatch", dataSource);
            // 查询
            
            IEnumerable<StaffInfo> staffInfos = mapperExecutor.ExecuteQueryDynamic<StaffInfo>("GetUserById", new
            {
                DepartmentId = "51336",
                TitleName = "主任中医师"
                //StaffName = "张三"
            });
            foreach (StaffInfo staffInfo in staffInfos)
            {
                string name = staffInfo.StaffName;
            }
            
        }

        /// <summary>
        /// Oracle测试
        /// </summary>
        [Obsolete]
        private static void OracleTest()
        {
            IEnumerable<StaffInfo> staffInfos = oracleMapperExecutor.ExcuteQuery<StaffInfo>("GetUserByIdOracle", new
            {
                StaffNo = "10010"
            });
            foreach (StaffInfo staffInfo in staffInfos)
            {
                string name = staffInfo.StaffName;
            }
        }
    }
}
